#!/bin/sh

_CurrentDIR="$PWD"
_CalledDIR=`echo $0 | awk -F '/' '{for (i=1;i<NF;i++) printf("%s/", $i); printf("\n")}'`

cd $_CalledDIR
export _SourceDIR="$PWD"
cd $_CurrentDIR

function _include()
{
    # $1 is the sh file that you want to source
    _ScriptFile="$1"
    _ScriptsDIR=`echo $_SourceDIR | awk -F '/' '{\
        for (i=1;i<=NF;i++)\
        {\
            printf("%s/", $i);\
            if ($i=="scripts") break\
        }\
        printf("\n")\
    }'`
    _CommonDIR="$_ScriptsDIR""auto/common/"
    _ScriptFullName=`find $_CommonDIR -name "$_ScriptFile"`

    if [ ! -z "$_ScriptFullName" ]
    then
        echo "Import $_ScriptFullName ......"
        . $_ScriptFullName
    else
        echo "Error while try to _include( $_ScriptFile )"
    fi
}

#echo $* | while read fn
#do
#    if [ ! -z "$fn" ]
#    then
#        _include $fn
#    fi
#done
